<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
      https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/
      思路：
      1、二分法：https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/solution/er-fen-cha-zhao-zhao-liang-ge-dan-zeng-qu-jian-de-/
      2、巧解：https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/solution/xuan-zhuan-shu-zu-zui-xiao-yuan-su-by-tanknee/
     */
    let numbers = [3,4,5,1,2];

    // 1、二分法：
    function minArray(numbers) {
      let left = 0;
      let right = numbers.length - 1;

      while (left < right) {
        let mid = left + right >> 1;

        if (numbers[mid] > numbers[right])
          left = mid + 1;
        else if (numbers[mid] < numbers[right])
          right = mid;
        else 
          right--;
      }

      return numbers[left];
    }

    // 2、巧解：
    function minArray(numbers) {
      for (let i = 0; i < numbers.length; i++) {
        if (numbers[0] > numbers[i])  return numbers[i];
      }
      
      return numbers[0];
    }
    console.log(minArray(numbers));
  </script>
</body>
</html>